package com.luoye.lj.wstool.wsdm;

import com.luoye.lj.wstool.generator.ICodeGenerator;
import com.luoye.lj.wstool.wsdm.entity.WsdtEntity;
import com.luoye.lj.wstool.wsdm.entity.WsdtField;

/*
 * Created with IntelliJ IDEA.
 * User: Dave Liu
 * Date: 2016/7/7
 * Time: 15:45
 * To change this template use File | Settings | File Templates.
 */
public class HtmlStatisticSetCodeGenerator implements ICodeGenerator {
    private WsdtEntity wsdtEntity;

    public HtmlStatisticSetCodeGenerator(WsdtEntity wsdtEntity) {
        this.wsdtEntity = wsdtEntity;
    }

    @Override
    public String codeGenerate() {
        String code="";
        if(this.wsdtEntity!=null){
            if(this.wsdtEntity.getFieldList()!=null){
                for(WsdtField wsdtField:this.wsdtEntity.getFieldList()){
                    String text="redata.entity."+wsdtField.getFieldName();
                    if(wsdtField.getFieldType().equals("Date")){
                        text="(new Date(redata.entity."+wsdtField.getFieldName()+")).Format(\"yyyy-MM-dd hh:mm\")";
                    }
                    if(wsdtField.getWsdtFieldDesc()==null) {
                        code+="                        \\$(\"#"+wsdtField.getFieldName()+"_statistic\").text("+text+");\n";
                    }else{
                        if(wsdtField.getWsdtFieldDesc().isStatistic()){
                            code+="                        \\$(\"#"+wsdtField.getFieldName()+"_statistic\").text("+text+");\n";
                        }
                    }
                }
            }
        }
        return code;
    }
}
